<template>
  <up-list v-if="attendanceGroups.length !== 0">
    <up-list-item v-for="attendanceGroup in attendanceGroups" :key="attendanceGroup.id">
      <view class="bg-white">
        <navigator :url="`/pages/admin/schedule/calendar?attendanceGroupId=${attendanceGroup.id}`">
          <up-cell :title="attendanceGroup.shop_name" is-link/>
        </navigator>
      </view>
    </up-list-item>
  </up-list>
  <up-empty v-else/>
</template>

<script lang="ts" setup>
import {ref} from "vue"
import {onPullDownRefresh} from "@dcloudio/uni-app";
import {LOADING} from "@/constant/loading";
import {getShops} from "@/api/shop";
import type ShopResponse from "@/api/types/ShopResponse";

const attendanceGroups = ref<ShopResponse[]>([])
let isLoadFromPullDown = false

async function getData() {
  if (!isLoadFromPullDown) {
    await uni.showLoading({title: LOADING})
  }
  const {data} = await getShops()
  if (data.data !== undefined) {
    attendanceGroups.value = data.data
    if (!isLoadFromPullDown) {
      uni.hideLoading()
    }
  }
}

getData()

onPullDownRefresh(async () => {
  isLoadFromPullDown = true
  await getData()
  uni.stopPullDownRefresh()
  isLoadFromPullDown = false
})
</script>
<style lang="scss" scoped>
.bg-white {
  background-color: white;
}
</style>
